package com.example.test0123spring;


import jakarta.servlet.http.Cookie;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpSession;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.net.http.HttpRequest;

@RestController
@RequestMapping("Test1")
public class Test1 {
    @RequestMapping("r1")
    public String func1(HttpServletRequest request ,@RequestParam(value = "aa" ,required=false) String s){
        Cookie[] cookies = request.getCookies();
        cookies[0].setAttribute("name","zhangsan");
        return s;
    }

    @RequestMapping("/r2")
    public String setCookie(HttpServletRequest request){
        Cookie[] cookies = request.getCookies();


        return "haha";

    }


    @RequestMapping("/r3")
    public String func(){
        return "kaixin1";
    }
    @RequestMapping("/r4")

    public void setSeesion(HttpServletRequest request){
        HttpSession session = request.getSession();
        session.setAttribute("name","lisiya");

    }

    @RequestMapping("/r5")
    public String getSession(HttpServletRequest request){
        HttpSession session = request.getSession();
        return (String)session.getAttribute("name");

    }
}
